package cn.schoolwow.quickdao.module.database.ddl.action.flow.column.renameTableColumn;

import cn.schoolwow.quickdao.domain.entity.Property;
import cn.schoolwow.quickdao.module.database.ddl.query.service.property.GetPropertyCompositeBusiness;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class CheckPropertyExistFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String tableName = (String) flowContext.checkData("tableName");
        String oldTableColumn = (String) flowContext.checkData("oldTableColumn");

        flowContext.startFlow(new GetPropertyCompositeBusiness())
                .putTemporaryData("tableName", tableName)
                .putTemporaryData("columnName", oldTableColumn)
                .execute();

        Property property = (Property) flowContext.getData("property");
        if(null==property){
            flowContext.broken("数据库表字段不存在!");
        }
    }

    @Override
    public String name() {
        return "检查字段是否存在";
    }
}
